{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入文章名称" value="" class="frm_input" />
        </span>
        <span>
            <select name="is_show" id="is_show" class="form-control" style="width:120px">
                <option value="">筛选是否显示</option>
                <option value="0">否</option>
                <option value="1">是</option>
            </select>
        </span>
        <span class="right">       
            
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加{$page_nav}</button>
        </span>

    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'title',width:250,align:'center',sortable: true">标题</th>
        <th data-options="field:'images',width:100,align:'center',formatter:formatImg">图片</th>
        </thead>
        <thead>
            <tr>
                <th data-options="field:'is_show',width:80,align:'center',formatter:isPublic">是否显示</th>
                <th data-options="field:'video_path',width:100,align:'center',formatter:formatVideo">视频</th>
                <th data-options="field:'intro',width:200,align:'center'">描述</th>
                <th data-options="field:'praise_number',width:80,align:'center'">点赞次数</th>
                <th data-options="field:'create_time',width:120,align:'center'">添加时间</th>
                <th data-options="field:'update_time',width:120,align:'center'">修改时间</th>
                <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
    function formatImg(value) {
        html = '';
        if(value!=null){
            html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
        }
        return html;

    }
    function openVideo(path){
        var url = getURL('play')+'?path='+path;
        openBarWin('播放视频', 1000, 600, url, function () {
            reload();
        });
    }
    function formatVideo(value, row, index) {
        html = '';
        if(value!=null){
            html = '<video src="'+value+'" style="max-width:50px;max-height:20px;text-align: center" onclick="openVideo(\''+value+'\')"></video>';
        }
        return html;
    }
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>删除</button>';
        html += '</span>';
        return html;
    }

    function isType(value, row, index){
        var text = '<span style="color:green">视频</span>';
        if(value == 1){
            text = '<span style="color:green">文章</span>';
        }else if(value == 2){
            text = '<span style="color:green">音频</span>';

        }
        return text;
    }

    function isPublic(value, row, index){
        var text = '<span style="color:red">是</span>';
        if(value == 0){
            text = '<span style="color:green">否</span>';
        }
        return text;
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

    function edit(id) {
        var url = getURL('news_post', 'id=' + id);
        openBarWin('编辑商学院', 1000, 600, url, function () {
            reload();
        }, ['保存', '取消']);
    }

    function del(id) {
        confirm("确认要删除此商学院吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }



    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('news_post');
        openBarWin('添加商学院', 1000, 600, url, function () {
            reload();
        });
    });
    
    $("#js_search").click(function () {
        reload();
    });
    $("#is_show").change(function () {
        reload();
    });
    function reload()
    {
        var keyword = $("#js_keyword").val();
        var is_show = $("#is_show").val();
        $('#grid-table').datagrid('reload', {is_show:is_show,keyword: keyword});
    }
</script>
{/block}